﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BilbilDAL;
using Common;
using Modles.DTO;
using Modles.Models;

namespace BilbilBLL
{
    public class ManageImageServer
    {
        ImageDAL imageDAL = new ImageDAL();
        public ResponseTool GetImagesByIdOrDescription(int Id, string Description)
        {
            return ResponseTool.Succeed(imageDAL.GetImagesByIdOrDescription(Id, Description));
        }
        public ResponseTool AddImage(Image_DTO image)
        {
            if (image.Address == null) { return ResponseTool.Fail("图片地址不能为空"); }
            if (image.Description == null) { return ResponseTool.Fail("图片描述不能为空"); }
            if (imageDAL.AddImage(image))
            {
                return ResponseTool.Succeed("添加成功");
            }
            else
            {
                return ResponseTool.Fail("添加失败");
            }
        }
        public ResponseTool DeleteImage(int Id)
        {
            if (Id == 0) { return ResponseTool.Fail("图片Id不能为空"); }
            if (imageDAL.DeleteImage(Id))
            {
                return ResponseTool.Succeed("删除成功");
            }
            else
            {
                return ResponseTool.Fail("删除失败");
            }
        }
        public ResponseTool UpdataImage(Image image)
        {
            if (image.Id == 0) { return ResponseTool.Fail("图片地址不能为空"); }
            if (image.Address == null) { return ResponseTool.Fail("图片地址不能为空"); }
            if (image.Description == null) { return ResponseTool.Fail("图片描述不能为空"); }
            if (imageDAL.UpdataImage(image))
            {
                return ResponseTool.Succeed("修改成功");
            }
            else
            {
                return ResponseTool.Fail("修改失败");
            }
        }
    }
}
